package 华为OD机试B卷复用题.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ7_篮球比赛 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/进阶题/input/7.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static int[] nums;
    static int res = Integer.MAX_VALUE, temp = 0, total = 0;
    // 经典类背包递归题，
    static void Solution(Scanner in) {
        String[] sArray = in.nextLine().split(" ");
        int len = sArray.length;
        nums = new int[len];
        for (int i = 0; i < len; i++) {
            nums[i] = Integer.parseInt(sArray[i]);
            total += nums[i];
        }
        dfs(0, 0);
        System.out.println(res);
    }

    static void dfs(int startIndex, int count) {
        if (startIndex == 10) {
            return;
        }
        if (count == 5) {
            // 求最小差值
            res = Math.min(Math.abs(total - temp - temp), res);
            return;
        }
        // 选择该数
        temp += nums[startIndex];
        dfs(startIndex + 1, count + 1);
        // 相关操作
        temp -= nums[startIndex];
        // 不选择该数
        dfs(startIndex + 1, count);
    }
}
